<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <ul>
        <li>Coffee</li>
        <li>Tea</li>
    </ul>
    <p id="demo">单击按钮更改列表项,使用createDocumentFragment方法,然后在列表的最后一个孩子添加列表项。</p>
    <button onclick="myFunction()">点我</button>
    <script>
        function sendAjax(method, url){
    return new Promise((resolve, reject) => {
        let xhr = new XMLHttpRequest();

        xhr.open(method, url);

        xhr.onreadystatechange = function(){
            if(this.readyState === 4){
                if(this.status >= 200 && this.status < 300){
                    resolve(JSON.parse(this.response))
                }else{
                    reject(this.status);
                }
            }
        }

        xhr.send();
    })
}


async function main(){
    try{
        let result = await sendAjax('GET', 'https://api.apiopen.top/getJoke');
        console.log(result);
    }catch(e){
        console.error(e);
    }
}

main();
        
    </script>
</body>

</html>